package com.wxtl.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Repository;

import com.wxtl.dao.base.HibernateBaseDao;
import com.wxtl.entity.Content;
import com.wxtl.util.DataGridModel;
import com.wxtl.util.Page;

/**
 * ContentDao
 * @author liulin
 *
 */
@Repository
public class ContentDAO extends HibernateBaseDao {
	private static final Log log = LogFactory.getLog(ContentDAO.class);
	
	/**
	 * 根据content查询
	 * @param dgm
	 * @param content
	 * @return
	 */
	public Page query(DataGridModel dgm,Content content){
		//构建hql
		StringBuilder hql=new StringBuilder();
		List<Object> params=new ArrayList<Object>();
		hql.append("from Content c where 1=1");
		if(content.getContent()!=null&&!"".equals(content.getContent())){
			params.add("%"+content.getContent()+"%");
			hql.append(" and c.content like ?");
		}
		return super.queryForList(hql.toString(), params.toArray(new Object[]{}), dgm.getPage(), dgm.getRows());
	}
	
	public Content load(int contentId){
		return (Content) getHibernateTemplate().load(Content.class, contentId);
	}
	
	public void delete(int[] ids){
		//直接删除
		super.delete("content","contentId", ids);
		//执行软删除
		//super.deleteByMark("content", "contentId", ids);
	}
	
	/**
	 * 获取所有目录
	 * @return
	 */
	public List<Content> queryAllContent(){
		String hql="from Content c";
		List<Content> list= getHibernateTemplate().find(hql);
		return list;
	}
}